package com.itheima.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;
@Component
public class AckListener implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        //签收多个信息
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
                //接收转换信息
                System.out.println(new String(message.getBody()));

                System.out.println("处理业务逻辑....");

                //手动签收
                channel.basicAck(deliveryTag,true);
            }catch (Exception e) {
            //拒绝签收:b1->重回队列
            channel.basicNack(deliveryTag, true, true );
        }
    }
}
